<template>
  <el-container class="layout-container">
    <el-header height="60px">
      <div class="header-title">客户订购系统</div>
      <div class="header-user">
        <span>{{ admin?.username }}</span>
        <el-button type="text" @click="logout">退出登录</el-button>
      </div>
    </el-header>
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

const router = useRouter()
const admin = ref(null)

onMounted(() => {
  const adminStr = localStorage.getItem('admin')
  if (adminStr) {
    admin.value = JSON.parse(adminStr)
  }
})

const logout = () => {
  localStorage.removeItem('admin')
  ElMessage.success('退出成功')
  router.push('/login')
}
</script>

<style scoped>
.layout-container {
  height: 100%;
  width: 100%;
}

.el-header {
  background-color: #409EFF;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px !important;
  line-height: 60px;
}

.header-title {
  font-size: 20px;
  font-weight: bold;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.el-button {
  color: white;
}

:deep(.el-main) {
  overflow-x: hidden;
  padding: 20px;
}
</style>
